package com.moore.attendance.udp;

/**
 * Created by MooreLi on 2017/6/5.
 */

public class ParseUdpUtil {
    public static UdpPackage getPackage(String info) {
        if (info != null) {
            info = info.substring(1, info.length() - 1);
            UdpPackage udpPackage = new UdpPackage();
            String[] infoList = info.split(",");
            if (infoList.length < 3) {
                return null;
            }
            udpPackage.setPackageNum(infoList[0]);
            udpPackage.setDeviceId(infoList[1]);
            if (infoList.length == 3) {
                udpPackage.setPackageCode(infoList[2]);
            } else if (infoList.length == 4) {
                udpPackage.setOtherInfo(infoList[2]);
                udpPackage.setPackageCode(infoList[3]);
            }
            return udpPackage;
        }
        return null;
    }
}
